package lanou.autohome.recommend;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;

import java.util.ArrayList;

import lanou.autohome.R;
import lanou.autohome.SouSuoActivity;
import lanou.autohome.recommend.fragments.BulletinFragment;
import lanou.autohome.recommend.fragments.ConversionFragment;
import lanou.autohome.recommend.fragments.CultureFragment;
import lanou.autohome.recommend.fragments.EvaluationFragment;
import lanou.autohome.recommend.fragments.GachincoFragment;
import lanou.autohome.recommend.fragments.GuideFragment;
import lanou.autohome.recommend.fragments.NewsFragment;
import lanou.autohome.recommend.fragments.OriginalityVideoFragment;
import lanou.autohome.recommend.fragments.QuotationFragment;
import lanou.autohome.recommend.fragments.SpeakerFragment;
import lanou.autohome.recommend.fragments.TechnologyFragment;
import lanou.autohome.recommend.fragments.TravelsFragment;
import lanou.autohome.recommend.fragments.UseCarFragment;
import lanou.autohome.recommend.fragments.VideoFragment;

/**
 * Created by dllo on 16/8/15.
 * 推荐
 */
public class RecommendFragment extends Fragment {

    private TabLayout tabLayout;
    private ViewPager viewPager;
    ArrayList<Fragment>fragments;
    private RecommendAdapter recommendAdapter;
    private ImageButton imageButton;

    @Nullable
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_recommend , null);

        tabLayout = (TabLayout) view.findViewById(R.id.recommend_tablayout);
        viewPager = (ViewPager) view.findViewById(R.id.recommend_viewpager);
        imageButton = (ImageButton) view.findViewById(R.id.btn_sousuo);
//        FragmentManager fragmentManager = getChildFragmentManager();
//        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        imageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()) {
                    case R.id.btn_sousuo:
                        Intent intent = new Intent(getContext(), SouSuoActivity.class);
                        startActivity(intent);
                }
            }
        });

        recommendAdapter = new RecommendAdapter(getChildFragmentManager());
        fragments = new ArrayList<>();

        fragments.add(new GachincoFragment());
        fragments.add(new BulletinFragment());
        fragments.add(new VideoFragment());
        fragments.add(new NewsFragment());
        fragments.add(new EvaluationFragment());
        fragments.add(new GuideFragment());
        fragments.add(new QuotationFragment());
        fragments.add(new UseCarFragment());
        fragments.add(new TechnologyFragment());
        fragments.add(new CultureFragment());
        fragments.add(new ConversionFragment());
        fragments.add(new TravelsFragment());
        fragments.add(new OriginalityVideoFragment());
        fragments.add(new SpeakerFragment());

        recommendAdapter.setFragments(fragments);
        viewPager.setAdapter(recommendAdapter);
        tabLayout.setupWithViewPager(viewPager);

        return view;
    }

}